package com.example.wechat_home_page;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.yanzhenjie.recyclerview.OnItemMenuClickListener;
import com.yanzhenjie.recyclerview.SwipeMenu;
import com.yanzhenjie.recyclerview.SwipeMenuBridge;
import com.yanzhenjie.recyclerview.SwipeMenuCreator;
import com.yanzhenjie.recyclerview.SwipeMenuItem;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        intview();
    }
    public void intview(){
        SwipeRecyclerView recyclerView=findViewById(R.id.recy_swip);
        SmartRefreshLayout refreshLayout=findViewById(R.id.refre_lay);
      recyclerView.setLayoutManager(new LinearLayoutManager(this));
        List<RecyBean> list=new ArrayList<>();
        String[] listname=new String[]{"微信运动","微信支付","Vic","powerbee","文件传输助手","wangping",
        "KaK","定西反诈","向前看","A000租房"};
        int[] listid=new int[]{R.mipmap.weixing,R.mipmap.zhifu,R.mipmap.huangyuan,R.mipmap.fendian,
                R.mipmap.file,R.mipmap.wang,R.mipmap.shen,R.mipmap.fanzha,R.mipmap.guo,R.mipmap.zufang};
        String[] datetime=new String[]{"8:02","8:30","8:45","9:05","10:14","10:25","11:55","12:36","13:54","14:22"};
        String[] dataname=new String[]{"[微信运动]","微信支付凭证","对","守万家灯火，候春暖花开","[图片]","嗯嗯",
        "马上","定西市一周电诈警情预警","发一下","好的"};
        for(int i=0;i<listname.length;i++){
            RecyBean recyBean=new RecyBean();
            recyBean.setRecyname(listname[i]);
            recyBean.setRecyid(listid[i]);
            recyBean.setTime(datetime[i]);
            recyBean.setInput(dataname[i]);
            list.add(recyBean);
        }


        List<RecyBean> data=new ArrayList<>();
        String[] datename=new String[]{"聂风","步惊云","明月","清霜","雄霸","梦",
                "孔慈","康熙","勇者","乾隆"};
        int[] dateid=new int[]{R.mipmap.zhao,R.mipmap.kun,R.mipmap.chai,R.mipmap.app,
                R.mipmap.yu,R.mipmap.nai,R.mipmap.gu,R.mipmap.bo,R.mipmap.yong,R.mipmap.qian};
        String[] listtime=new String[]{"14:32","14:40","14:55","15:05","15:14","15:40","16:05","16:36","17:34","18:22"};
        String[] datname=new String[]{"图片","ok","你好","在吗","干啥","再见",
                "视频通话","语音通话","强","好"};
        for(int i=0;i<datename.length;i++){
            RecyBean recyBean=new RecyBean();
            recyBean.setRecyname(datename[i]);
            recyBean.setRecyid(dateid[i]);
            recyBean.setTime(listtime[i]);
            recyBean.setInput(datname[i]);
            data.add(recyBean);
        }

       MyAdaper adaper=new MyAdaper(MainActivity.this);
        adaper.setData(list);


        SwipeMenuCreator menuCreator=new SwipeMenuCreator() {
            @Override
            public void onCreateMenu(SwipeMenu leftMenu, SwipeMenu rightMenu, int position) {
                SwipeMenuItem item=new SwipeMenuItem(MainActivity.this);
                item.setBackground(R.color.design_default_color_error);
                item.setText("删除");
                item.setTextSize(16);
                item.setTextColor(Color.WHITE);
                item.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
                item.setWeight(180);
                rightMenu.addMenuItem(item);
                SwipeMenuItem item1=new SwipeMenuItem(MainActivity.this);
                item1.setBackground(R.color.design_default_color_secondary);
                item1.setText("置顶");
                item1.setTextSize(16);
                item1.setTextColor(Color.WHITE);
                item1.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
                item1.setWeight(180);
                rightMenu.addMenuItem(item1);

            }
        };

        recyclerView.setSwipeMenuCreator(menuCreator);
        recyclerView.setOnItemMenuClickListener(new OnItemMenuClickListener() {
            @Override
            public void onItemClick(SwipeMenuBridge menuBridge, int adapterPosition) {
                if(menuBridge.getDirection()==SwipeRecyclerView.RIGHT_DIRECTION){
                    if(menuBridge.getPosition()==1){
                        menuBridge.closeMenu();
                    }
                }
            }
        });
        recyclerView.setAdapter(adaper);

        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull  RefreshLayout refreshLayout) {
                list.clear();
                list.addAll(data);
                adaper.notifyDataSetChanged();
              refreshLayout.finishRefresh(2000,true,false);
            }
        });
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull  RefreshLayout refreshLayout) {
                list.addAll(data);
                adaper.notifyDataSetChanged();
                refreshLayout.finishRefresh(2000,true,true);
            }
        });


    }
}